/**
 * Copyright (c) 2018, wuxie All rights reserved.
 * qq:16349023,mail:16349023@qq.com
 * 未经许可禁止任何人通过任何渠道使用、修改源代码.
 * 项目名称 : wxcloud
 *
 * @version V1.0
 */
package cn.xo68.boot.auth.server.mapper;

import cn.xo68.boot.auth.server.domain.OauthClient;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 *  Oauth2Client mapper
 * @author wuxie
 * @date 2018/8/4 11:36
 *
 */
public interface OauthClientMapper {

    @Select("SELECT * FROM oauth_client WHERE client_id = #{clientId}")
    @Results(value = {
            @Result(id = true, column = "client_id", property = "clientId"),
            @Result(column = "resource_ids", property = "resourceIds"),
            @Result(column = "client_secret", property = "clientSecret"),
            @Result(column = "client_name", property = "clientName"),
            @Result(column = "scope", property = "scope"),
            @Result(column = "authorized_grant_types", property = "authorizedGrantTypes"),
            @Result(column = "client_type", property = "clientType"),
            @Result(column = "client_status", property = "clientStatus"),
            @Result(column = "web_home_url", property = "webHomeUrl"),
            @Result(column = "web_server_redirect_uri", property = "webServerRedirectUri"),
            @Result(column = "authorities", property = "authorities"),
            @Result(column = "access_token_validity", property = "accessTokenValidity"),
            @Result(column = "refresh_token_validity", property = "refreshTokenValidity"),
            @Result(column = "additional_information", property = "additionalInformation"),
            @Result(column = "auto_approve", property = "autoApprove"),
            @Result(column = "order_value", property = "orderValue"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime")
    })
    OauthClient get(@Param("clientId") String clientId);

    @Select("SELECT * FROM oauth_client WHERE client_id = #{clientId}")
    @Results(value = {
            @Result(id = true, column = "client_id", property = "clientId"),
            @Result(column = "resource_ids", property = "resourceIds"),
            @Result(column = "client_secret", property = "clientSecret"),
            @Result(column = "client_name", property = "clientName"),
            @Result(column = "scope", property = "scope"),
            @Result(column = "authorized_grant_types", property = "authorizedGrantTypes"),
            @Result(column = "client_type", property = "clientType"),
            @Result(column = "client_status", property = "clientStatus"),
            @Result(column = "web_home_url", property = "webHomeUrl"),
            @Result(column = "web_server_redirect_uri", property = "webServerRedirectUri"),
            @Result(column = "authorities", property = "authorities"),
            @Result(column = "access_token_validity", property = "accessTokenValidity"),
            @Result(column = "refresh_token_validity", property = "refreshTokenValidity"),
            @Result(column = "additional_information", property = "additionalInformation"),
            @Result(column = "auto_approve", property = "autoApprove"),
            @Result(column = "order_value", property = "orderValue"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime")
    })
    OauthClient find(@Param("clientId") String clientId);

    @Select("SELECT * FROM oauth_client order by order_value")
    @Results(value = {
            @Result(id = true, column = "client_id", property = "clientId"),
            @Result(column = "resource_ids", property = "resourceIds"),
            @Result(column = "client_secret", property = "clientSecret"),
            @Result(column = "client_name", property = "clientName"),
            @Result(column = "scope", property = "scope"),
            @Result(column = "authorized_grant_types", property = "authorizedGrantTypes"),
            @Result(column = "client_type", property = "clientType"),
            @Result(column = "client_status", property = "clientStatus"),
            @Result(column = "web_home_url", property = "webHomeUrl"),
            @Result(column = "web_server_redirect_uri", property = "webServerRedirectUri"),
            @Result(column = "authorities", property = "authorities"),
            @Result(column = "access_token_validity", property = "accessTokenValidity"),
            @Result(column = "refresh_token_validity", property = "refreshTokenValidity"),
            @Result(column = "additional_information", property = "additionalInformation"),
            @Result(column = "auto_approve", property = "autoApprove"),
            @Result(column = "order_value", property = "orderValue"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime")
    })
    List<OauthClient> list();

    @Insert("insert into oauth_client (client_id ,resource_ids ,client_secret ,client_name ,scope ,authorized_grant_types ,client_type ,client_status ,web_home_url ,web_server_redirect_uri ,authorities ,access_token_validity ,refresh_token_validity ,additional_information ,auto_approve,order_value, create_time,update_time ) values (#{clientId} , #{resourceIds} , #{clientSecret} , #{clientName} , #{scope} , #{authorizedGrantTypes} , #{clientType} , #{clientStatus} , #{webHomeUrl} , #{webServerRedirectUri} , #{authorities} , #{accessTokenValidity} , #{refreshTokenValidity} , #{additionalInformation} , #{autoApprove} ,#{orderValue} , #{createTime} , #{updateTime} )")
    @Options(useGeneratedKeys = true, keyProperty = "clientId")
    void insert(OauthClient oauth2Client);

    @Update("update oauth_client set  resource_ids=#{resourceIds}, client_secret=#{clientSecret}, client_name=#{clientName}, scope=#{scope}, authorized_grant_types=#{authorizedGrantTypes}, client_type=#{clientType}, web_home_url=#{webHomeUrl}, additional_information=#{additionalInformation}, auto_approve=#{autoApprove},update_time=#{updateTime} where client_id = #{clientId}")
    void update(OauthClient oauth2Client);

    @Delete("delete FROM oauth_client WHERE client_id = #{clientId}")
    void delete(@Param("clientId") String clientId);
}
